package com.example.service.impl;

import com.example.entity.Best;
import com.example.mapper.BestMapper;
import com.example.service.BestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional(rollbackFor = Exception.class)
public class BestServiceImpl implements BestService {

    @Autowired
    BestMapper bestMapper;

    @Override
    public int getBestCountWithRId(Integer rid) {
        return bestMapper.getBestCountWithRId(rid);
    }

    @Override
    public Boolean checkWeatherIsSelected(Integer userid, Integer rid) {
        Best best = bestMapper.checkWeatherIsSelected(userid, rid);
        if (best == null) {
            return false;
        }
        return true;
    }

    @Override
    public void giveThumbsUp(Integer rid, Integer userid) {
        Best best = new Best();
        best.setRid(rid);
        best.setUserid(userid);
        bestMapper.insert(best);
    }

    @Override
    public void abolishGiveThumbsUp(Integer rid, Integer userid) {
        bestMapper.deleteByUserAndRecommend(userid, rid);
    }

}